var entry = {
    a: {
        b: {
            c: {
                dd: 'abcdd'
            }
        },
        d: {
            xx: 'adxx'
        },
        e: 'ae'
    }
}
// 要求转换成如下对象
var output = {
    'a.b.c.dd': 'abcdd',
    'a.d.xx': 'adxx',
    'a.e': 'ae'
}
// 利用递归实现
function flatObj(obj = {}, pkey = "", result={}) {
    for (const key in obj) {
        if (obj.hasOwnProperty(key)) {
            let ckey = `${pkey}${key}`
            if (typeof obj[key] == "object") {
                flatObj(obj[key], ckey+".", result)
            } else {
                result[ckey] = obj[key]
            }
        }
    }
    return result
}
console.log(flatObj(entry))



var entry2 = {
    'a.b.c.dd': 'abcdd',
    'a.d.xx': 'adxx',
    'a.e': 'ae'
}
// 要求转换成如下对象
var output2 = {
    a: {
        b: {
            c: {
                dd: 'abcdd'
            }
        },
        d: {
            xx: 'adxx'
        },
        e: 'ae'
    }
}
function map(entry = {}) {
    let obj = {};
    for (const key in entry) {
        if (entry.hasOwnProperty(key)) {
            const ckey = key.split(".")
            set(obj, ckey, entry[key])
        }
    }
    return obj
}
function set(obj, arr, val) {
    if (!obj[arr[0]]) obj[arr[0]] = {};
    let temp = obj[arr[0]];
    for (let i = 1; i < arr.length; i++) {
        if (!temp[arr[i]]) {
            if (i === arr.length - 1) {
                temp[arr[i]] = val
            } else {
                temp[arr[i]] = {}
            }
        }
        temp = temp[arr[i]] // 指针改变
    }
}
console.log(JSON.stringify(map(entry2)))